#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 1e5 + 5;

int n, m;
struct Edge {
  int u, v, w;
  bool operator<(Edge e) const { return w < e.w; }
} a[N];
struct Qus {
  int k, v, id;
  bool operator<(Qus x) const { return k < x.k; }
} q[N];
int ans[N];
int f[N], sz[N];
void init() { rep(i, 1, n) f[i] = i, sz[i] = 1; }
int find(int x) { return f[x] == x ? x : f[x] = find(f[x]); }
void merge(int x, int y) {
  int fx = find(x), fy = find(y);
  if (fx != fy) {
    f[fy] = fx;
    sz[fx] += sz[fy];
  }
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> m;
  rep(i, 1, n - 1) cin >> a[i].u >> a[i].v >> a[i].w;
  rep(i, 1, m) {
    cin >> q[i].k >> q[i].v;
    q[i].id = i;
  }
  sort(a + 1, a + n);
  sort(q + 1, q + m + 1);
  init();
  int j = n - 1;
  per(i, m, 1) {
    while (j && a[j].w >= q[i].k) {
      merge(a[j].u, a[j].v);
      j--;
    }
    int fv = find(q[i].v);
    ans[q[i].id] = sz[fv] - 1;
  }
  rep(i, 1, m) cout << ans[i] << endl;
  return 0;
}